package com.ffcs.cn.action.scene.layersetting;

import com.ffcs.cn.DevelopProperties;
import com.ffcs.cn.action.common.StyleSettingPaneLine;
import com.ffcs.cn.action.common.StyleSettingPanelManager;
import com.ffcs.cn.action.common.StyleSettingPanelPoint;
import com.ffcs.cn.action.common.StyleSettingPanelRegion;
import com.supermap.data.GeoStyle3D;
import com.supermap.data.SymbolType;
import com.supermap.desktop.controls.ui.UICommonToolkit;
import com.supermap.desktop.controls.ui.controls.SmDialog;
import com.supermap.desktop.controls.ui.trees.Layer3DsTree;
import com.supermap.desktop.controls.ui.trees.TreeNodeData;
import com.supermap.desktop.core.event.colorSelect.ColorChangedEvent;
import com.supermap.desktop.core.event.colorSelect.ColorChangedListener;
import com.supermap.desktop.core.event.colorSelect.IColorChangedListener;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;
import com.supermap.desktop.core.utilties.ColorUtilities;
import com.supermap.desktop.core.utilties.ComponentUIUtilities;
import com.supermap.desktop.core.utilties.Layer3DUtilities;
import com.supermap.desktop.core.utilties.SymbolTypeUtilities;
import com.supermap.realspace.Layer3D;
import com.supermap.realspace.Layer3DDataset;
import com.supermap.realspace.Layer3DSettingVector;
import com.supermap.realspace.ShadowType;

import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

/**
 * 场景风格设置
 *
  */
public class DialogLayerSettingScene extends SmDialog {

	private StyleSettingPanelManager styleSettingPanelManager;
	/**
	 * 图层名
	 **/
	private JLabel labelLayerName;
	private JTextField textFieldLayerName;

	/**
	 * 阴影模式
	 **/
	private JLabel labelShadowType;
	private JComboBox<ShadowType> comboBoxShadowType;

	/**
	 * 是否可显示
	 **/
	private JCheckBox checkboxDisplayable;
	/**
	 * 是否可编辑
	 **/
	private JCheckBox checkBoxEditable;
	/**
	 * 是否可选择
	 **/
	private JCheckBox checkBoxSelectable;


	private final StyleSettingPanelRegion styleSettingPanelRegion = new StyleSettingPanelRegion() {

		@Override
		public IColorChangedListener getForceColorChangedListener() {
			return new ColorChangedListener() {
				@Override
				public void colorChanged(ColorChangedEvent colorChangedEvent) {
					Layer3D layer3D = getSelectedNodeLayer()[0];
					if (layer3D instanceof Layer3DDataset) {
						// 获取当前风格
						GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
						// 设置前景色
						oldGeoStyle.setFillForeColor(colorChangedEvent.getColor());
						((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
						layer3D.updateData();
					}
				}
			};
		}

		@Override
		public IColorChangedListener getBackgroundColorChangedListener() {
			return new ColorChangedListener() {
				@Override
				public void colorChanged(ColorChangedEvent colorChangedEvent) {
					Layer3D layer3D = getSelectedNodeLayer()[0];
					if (layer3D instanceof Layer3DDataset) {
						// 获取当前风格
						GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
						// 设置背景色
						oldGeoStyle.setFillBackColor(colorChangedEvent.getColor());
						((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
						layer3D.updateData();
					}
				}
			};
		}

		@Override
		public ChangeListener getOpaqueChangeListener() {
			return e -> {
				Layer3D layer3D = getSelectedNodeLayer()[0];
				if (layer3D instanceof Layer3DDataset) {
					// 获取当前风格
					GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
					// 设置透明度
					Color color = new Color(oldGeoStyle.getFillForeColor().getRed(),
							oldGeoStyle.getFillForeColor().getGreen(),
							oldGeoStyle.getFillForeColor().getRed(),
							ColorUtilities.getAlpha((int) spinnerOpaque.getValue()));
					oldGeoStyle.setFillForeColor(color);
					((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
					layer3D.updateData();
				}
			};
		}

		@Override
		public void itemChange() {
			if (getSelectedNodeLayer().length != 1) {
				buttonBackgroundColor.setEnabled(false);
				buttonForceColor.setEnabled(false);
				spinnerOpaque.setEnabled(false);
				return;
			}
			buttonBackgroundColor.setEnabled(true);
			buttonForceColor.setEnabled(true);
			spinnerOpaque.setEnabled(true);
			GeoStyle3D geoStyle3D = Layer3DUtilities.getGeoStyle3D(getSelectedNodeLayer()[0]);
			buttonBackgroundColor.setColor(geoStyle3D.getFillBackColor());
			buttonForceColor.setColor(geoStyle3D.getFillForeColor());
			spinnerOpaque.setValue(ColorUtilities.getTransparency(geoStyle3D.getFillForeColor().getAlpha()));
		}
	};

	private final StyleSettingPanelPoint styleSettingPanelPoint = new StyleSettingPanelPoint() {
		@Override
		public IColorChangedListener getSymbolColorChangeListener() {
			return new ColorChangedListener() {
				@Override
				public void colorChanged(ColorChangedEvent colorChangedEvent) {
					Layer3D layer3D = getSelectedNodeLayer()[0];
					if (layer3D instanceof Layer3DDataset) {
						// 获取当前风格
						GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
						// 设置符号颜色
						oldGeoStyle.setLineColor(colorChangedEvent.getColor());
						((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
						layer3D.updateData();
					}
				}
			};
		}

		@Override
		public ChangeListener getHeightChangeListener() {
			return e -> {
				Layer3D layer3D = getSelectedNodeLayer()[0];
				if (layer3D instanceof Layer3DDataset) {
					// 获取当前风格
					GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
					// 设置符号高度
					oldGeoStyle.setMarkerSize(((double) spinnerHeight.getValue()));
					((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
					layer3D.updateData();
				}
			};
		}

		@Override
		public ChangeListener getWidthChangeListener() {
			return e -> {
				Layer3D layer3D = getSelectedNodeLayer()[0];
				if (layer3D instanceof Layer3DDataset) {
					// 获取当前风格
					GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
					// 设置符号宽度
					oldGeoStyle.setMarkerSize(((double) spinnerWidth.getValue()));
					((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
					layer3D.updateData();
				}
			};
		}

		@Override
		public ChangeListener getMarkerAngleChangeListener() {
			// 场景里不能够设置点符号旋转角度
			return null;
		}

		@Override
		public ChangeListener getAlphaChangeListener() {
			// 场景里不能够设置点符号透明度
			return null;
		}

		@Override
		public void itemChange() {
			spinnerOpaqueRate.setEnabled(false);
			spinnerMarkerAngle.setEnabled(false);
			if (getSelectedNodeLayer().length != 1) {
				buttonSymbolColor.setEnabled(false);
				spinnerWidth.setEnabled(false);
				spinnerHeight.setEnabled(false);
				return;
			}
			buttonSymbolColor.setEnabled(true);
			spinnerWidth.setEnabled(true);
			spinnerHeight.setEnabled(true);
			GeoStyle3D geoStyle3D = Layer3DUtilities.getGeoStyle3D(getSelectedNodeLayer()[0]);
			if (geoStyle3D != null) {
				buttonSymbolColor.setColor(geoStyle3D.getLineColor());
				spinnerWidth.setValue(geoStyle3D.getMarkerSize());
				spinnerHeight.setValue(geoStyle3D.getMarkerSize());
			}
		}
	};

	private final StyleSettingPaneLine styleSettingPaneLine = new StyleSettingPaneLine() {
		@Override
		public IColorChangedListener getLineColorChangedListener() {
			return new ColorChangedListener() {
				@Override
				public void colorChanged(ColorChangedEvent colorChangedEvent) {
					Layer3D layer3D = getSelectedNodeLayer()[0];
					if (layer3D instanceof Layer3DDataset) {
						// 获取当前风格
						GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
						// 设置线颜色
						oldGeoStyle.setLineColor(colorChangedEvent.getColor());
						((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
						layer3D.updateData();
					}
				}
			};
		}

		@Override
		public ChangeListener getLineWidthChangeListener() {
			return e -> {
				Layer3D layer3D = getSelectedNodeLayer()[0];
				if (layer3D instanceof Layer3DDataset) {
					// 获取当前风格
					GeoStyle3D oldGeoStyle = Layer3DUtilities.getGeoStyle3D(layer3D);
					// 设置线宽
					oldGeoStyle.setMarkerSize(((double) spinnerLineWidth.getValue()));
					((Layer3DSettingVector) ((Layer3DDataset) layer3D).getAdditionalSetting()).setStyle(oldGeoStyle);
					layer3D.updateData();
				}
			};
		}

		@Override
		public void itemChange() {
			if (getSelectedNodeLayer().length != 1) {
				buttonLineColor.setEnabled(false);
				spinnerLineWidth.setEnabled(false);
				return;
			}
			buttonLineColor.setEnabled(true);
			spinnerLineWidth.setEnabled(true);
			GeoStyle3D geoStyle3D = Layer3DUtilities.getGeoStyle3D(getSelectedNodeLayer()[0]);
			buttonLineColor.setColor(geoStyle3D.getLineColor());
			spinnerLineWidth.setValue(geoStyle3D.getMarkerSize());
		}
	};

	private final ShadowType[] shadowTypes = new ShadowType[]{
			ShadowType.ALL, ShadowType.NONE, ShadowType.SELECTION
	};

	/**
	 * 监听鼠标点击图层树
	 */
	private final MouseAdapter mouseAdapter = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			initState();
		}
	};

	public DialogLayerSettingScene() {
		super(ComponentUIUtilities.getTopLevelFrame(), false);
		setTitle(DevelopProperties.getString("String_LayerSetting"));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setSize(new Dimension(400, 200));
		initComponents();
		initLayout();
		registerEvents();
		initState();
	}

	/**
	 * 从图层管理器树，获取当前选中的图层
	 *
	 * @return 当前选中的图层
	 */
	private Layer3D[] getSelectedNodeLayer() {
		List<Layer3D> layer3DList = new ArrayList<>();
		Layer3DsTree layer3DsTree = UICommonToolkit.getLayersManager().getLayer3DsTree();
		TreePath[] selectionPaths = layer3DsTree.getSelectionPaths();
		if (selectionPaths == null) {
			return new Layer3D[0];
		}
		for (TreePath selectionPath : selectionPaths) {
			if (selectionPath.getLastPathComponent() instanceof DefaultMutableTreeNode) {
				TreeNodeData treeNodeData = ((TreeNodeData) ((DefaultMutableTreeNode) selectionPath.getLastPathComponent()).getUserObject());
				if (treeNodeData.getData() instanceof Layer3D) {
					layer3DList.add(((Layer3D) treeNodeData.getData()));
				}
			}
		}
		return layer3DList.toArray(new Layer3D[0]);
	}

	private void initComponents() {
		checkboxDisplayable = new JCheckBox(DevelopProperties.getString("String_Displayable"));
		checkBoxEditable = new JCheckBox(DevelopProperties.getString("String_Editable"));
		checkBoxSelectable = new JCheckBox(DevelopProperties.getString("String_Selectable"));
		labelLayerName = new JLabel(DevelopProperties.getString("String_Label_LayerName"));
		textFieldLayerName = new JTextField();
		labelShadowType = new JLabel(DevelopProperties.getString("String_ShadowType"));
		comboBoxShadowType = new JComboBox<>(shadowTypes);
		comboBoxShadowType.setRenderer(new DefaultListCellRenderer() {
			@Override
			public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
				super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
				String text;
				if (value == ShadowType.ALL) {
					text = DevelopProperties.getString("String_ShadowType_ALL");
				} else if (value == ShadowType.NONE) {
					text = DevelopProperties.getString("String_ShadowType_NONE");
				} else {
					text = DevelopProperties.getString("String_ShadowType_SELECTION");
				}
				this.setText(text);
				return this;
			}

		});

		styleSettingPanelManager = new StyleSettingPanelManager();
		styleSettingPanelManager.add(styleSettingPaneLine);
		styleSettingPanelManager.add(styleSettingPanelPoint);
		styleSettingPanelManager.add(styleSettingPanelRegion);
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		JPanel checkBoxPanel = new JPanel();
		checkBoxPanel.setLayout(new GridBagLayout());
		checkBoxPanel.setBorder(BorderFactory.createEmptyBorder());
		checkBoxPanel.add(checkboxDisplayable, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.NONE)
				.setWeight(1, 0));
		checkBoxPanel.add(checkBoxSelectable, new GridBagConstraintsHelper(1, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.NONE)
				.setWeight(1, 0));
		checkBoxPanel.add(checkBoxEditable, new GridBagConstraintsHelper(2, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.NONE)
				.setWeight(1, 0));

		JPanel baseSettingPanel = new JPanel();
		baseSettingPanel.setLayout(new GridBagLayout());
		baseSettingPanel.setBorder(BorderFactory.createTitledBorder(DevelopProperties.getString("String_BaseSetting")));
		baseSettingPanel.add(checkBoxPanel, new GridBagConstraintsHelper(0, 0, 3, 1)
				.setAnchor(GridBagConstraints.CENTER)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		baseSettingPanel.add(labelLayerName, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		baseSettingPanel.add(textFieldLayerName, new GridBagConstraintsHelper(1, 1, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		baseSettingPanel.add(labelShadowType, new GridBagConstraintsHelper(0, 2, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		baseSettingPanel.add(comboBoxShadowType, new GridBagConstraintsHelper(1, 2, 2, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(baseSettingPanel, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));

		this.add(styleSettingPanelRegion, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(styleSettingPanelPoint, new GridBagConstraintsHelper(0, 2, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(styleSettingPaneLine, new GridBagConstraintsHelper(0, 3, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.WEST)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		this.add(new JPanel(), new GridBagConstraintsHelper(0, 4, 1, 1)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setAnchor(GridBagConstraints.CENTER)
				.setFill(GridBagConstraints.BOTH)
				.setWeight(1, 1));
	}

	private void registerEvents() {
		checkboxDisplayable.addChangeListener(e -> {
			if (getSelectedNodeLayer().length != 1) {
				return;
			}
			Layer3D layer3D = getSelectedNodeLayer()[0];
			if (!checkboxDisplayable.isSelected()) {
				layer3D.setVisible(false);
				checkBoxEditable.setSelected(false);
				checkBoxSelectable.setSelected(false);
				checkBoxEditable.setEnabled(false);
				checkBoxSelectable.setEnabled(false);
			} else {
				layer3D.setVisible(true);
				checkBoxEditable.setEnabled(true);
				checkBoxSelectable.setEnabled(true);
			}
			UICommonToolkit.getLayersManager().getLayer3DsTree().updateUI();
		});

		textFieldLayerName.getDocument().addDocumentListener(new DocumentListener() {
			private void setCaption() {
				if (getSelectedNodeLayer().length == 1) {
					Layer3D layer3D = getSelectedNodeLayer()[0];
					// 设置别名
					layer3D.setCaption(textFieldLayerName.getText());
					UICommonToolkit.getLayersManager().getLayer3DsTree().updateUI();
				}
			}

			@Override
			public void insertUpdate(DocumentEvent e) {
				setCaption();
			}

			@Override
			public void removeUpdate(DocumentEvent e) {
				setCaption();
			}

			@Override
			public void changedUpdate(DocumentEvent e) {

			}
		});

		checkBoxEditable.addChangeListener(e -> {
			if (getSelectedNodeLayer().length != 1) {
				return;
			}
			Layer3D layer3D = getSelectedNodeLayer()[0];
			layer3D.setEditable(checkBoxEditable.isSelected());
			UICommonToolkit.getLayersManager().getLayer3DsTree().updateUI();
		});

		checkBoxSelectable.addChangeListener(e -> {
			if (getSelectedNodeLayer().length != 1) {
				return;
			}
			Layer3D layer3D = getSelectedNodeLayer()[0];
			layer3D.setSelectable(checkBoxSelectable.isSelected());
			UICommonToolkit.getLayersManager().getLayer3DsTree().updateUI();
		});

		comboBoxShadowType.addItemListener(e -> {
			if (getSelectedNodeLayer().length != 1) {
				return;
			}
			Layer3D layer3D = getSelectedNodeLayer()[0];
			layer3D.setShadowType(((ShadowType) comboBoxShadowType.getSelectedItem()));
		});
		// 图层树添加监听器
		UICommonToolkit.getLayersManager().getLayer3DsTree().addMouseListener(mouseAdapter);
	}

	private void initState() {
		Layer3D[] selectedLayers = getSelectedNodeLayer();
		if (selectedLayers.length == 1) {
			Layer3D selectedLayer = selectedLayers[0];
			checkBoxEditable.setSelected(selectedLayer.isEditable());
			checkBoxSelectable.setSelected(selectedLayer.isSelectable());
			checkboxDisplayable.setSelected(selectedLayer.isVisible());
			textFieldLayerName.setText(selectedLayer.getCaption());
			comboBoxShadowType.setSelectedItem(selectedLayer.getShdowType());
		}
		checkboxDisplayable.setEnabled(selectedLayers.length == 1);
		checkBoxEditable.setEnabled(selectedLayers.length == 1);
		checkBoxSelectable.setEnabled(selectedLayers.length == 1);
		textFieldLayerName.setEnabled(selectedLayers.length == 1);
		comboBoxShadowType.setEnabled(selectedLayers.length == 1);
		if (getSelectedNodeLayer().length == 1
				&& selectedLayers[0] instanceof Layer3DDataset
				&& SymbolTypeUtilities.getSymbolType(((Layer3DDataset) selectedLayers[0]).getDataset().getType()) == SymbolType.FILL) {
			styleSettingPanelManager.setActivePanel(styleSettingPanelRegion);
		} else if (getSelectedNodeLayer().length == 1
				&& selectedLayers[0] instanceof Layer3DDataset
				&& SymbolTypeUtilities.getSymbolType(((Layer3DDataset) selectedLayers[0]).getDataset().getType()) == SymbolType.LINE) {
			styleSettingPanelManager.setActivePanel(styleSettingPaneLine);
		} else {
			styleSettingPanelManager.setActivePanel(styleSettingPanelPoint);
		}
		styleSettingPanelManager.getActivePanel().itemChange();
	}

	@Override
	public void dispose() {
		super.dispose();
		// 关闭对话框，要把对对话框外部添加的监听器移除
		UICommonToolkit.getLayersManager().getLayer3DsTree().removeMouseListener(mouseAdapter);
	}
}
